package com.zeta.eduservice.service.impl;

import com.zeta.eduservice.entity.EduClasss;
import com.zeta.eduservice.entity.and.EduClassAndPublichomework;
import com.zeta.eduservice.entity.and.EduCourseAndPublichomework;
import com.zeta.eduservice.entity.and.EduFolderAndPublichomework;
import com.zeta.eduservice.entity.question.EduCourse;
import com.zeta.eduservice.entity.question.EduFolder;
import com.zeta.eduservice.entity.question.EduPublishhomework;
import com.zeta.eduservice.entity.vo.PublishQuery;
import com.zeta.eduservice.entity.vo.front.PublishVo;
import com.zeta.eduservice.mapper.EduClassAndPublichomeworkMapper;
import com.zeta.eduservice.mapper.EduClasssMapper;
import com.zeta.eduservice.mapper.EduCourseMapper;
import com.zeta.eduservice.mapper.EduFolderAndPublichomeworkMapper;
import com.zeta.eduservice.mapper.EduFolderMapper;
import com.zeta.eduservice.mapper.EduPublishhomeworkMapper;
import com.zeta.eduservice.service.EduClassAndPublichomeworkService;
import com.zeta.eduservice.service.EduCourseAndPublichomeworkService;
import com.zeta.eduservice.service.EduFolderAndPublichomeworkService;
import com.zeta.eduservice.service.EduPublishhomeworkService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 发布作业 服务实现类
 * </p>
 *
 * @author zeta
 * @param <E>
 * @since 2020-11-10
 */
@Service
public class EduPublishhomeworkServiceImpl<E> extends ServiceImpl<EduPublishhomeworkMapper, EduPublishhomework> implements EduPublishhomeworkService {
	@Autowired
	EduFolderAndPublichomeworkService folderAndPublicHomeworkService;
	@Autowired
	EduClassAndPublichomeworkService classAndPublishService;
	@Autowired
	EduCourseAndPublichomeworkService courseAndPublishService;

	@Autowired 
	EduFolderMapper folderMapper;
	@Autowired
	EduCourseMapper courseMapper;
	@Autowired
	EduClasssMapper classMapper;
	@Override
	public void add(List<String> folerList, List<String> classList, List<String> courseList,EduPublishhomework publicHomework) {
		if(folerList!=null) {
			ArrayList<EduFolderAndPublichomework> arrayList = new ArrayList<EduFolderAndPublichomework>();
			for(String i:folerList) {
				EduFolderAndPublichomework eduFolderAndPublichomework = new EduFolderAndPublichomework();
				eduFolderAndPublichomework.setFolderId(i);
				eduFolderAndPublichomework.setPublishomeworkId(publicHomework.getId());
				arrayList.add(eduFolderAndPublichomework);
			}
			folderAndPublicHomeworkService.saveBatch(arrayList);
			
		}
		if(classList!=null) {
			ArrayList<EduClassAndPublichomework> arrayList2 = new ArrayList<EduClassAndPublichomework>();
			for(String i:classList) {
				EduClassAndPublichomework eduClassAndPublichomework = new EduClassAndPublichomework ();
				eduClassAndPublichomework.setPublishomeworkId(publicHomework.getId());
				eduClassAndPublichomework.setClassId(i);
				arrayList2.add(eduClassAndPublichomework);
			}
			classAndPublishService.saveBatch(arrayList2);
			
		}
		if(courseList!=null) {
			ArrayList<EduCourseAndPublichomework> arrayList3 = new ArrayList<EduCourseAndPublichomework>();
			for(String i:courseList) {
				EduCourseAndPublichomework eduCourseAndPublichomework = new EduCourseAndPublichomework();
				eduCourseAndPublichomework.setCourseId(i);
				eduCourseAndPublichomework.setPublishomeworkId(publicHomework.getId());
				arrayList3.add(eduCourseAndPublichomework);
			}
			courseAndPublishService.saveBatch(arrayList3);
		}
	
		
	}
	@Override
	public PublishVo getList(String id) {
	List<EduFolder> byPublishId = folderMapper.getByPublishId(id);
	List<EduCourse> byPublishId2 = courseMapper.getByPublishId(id);
	List<EduClasss> byPublishId3 = classMapper.getByPublishId(id);
	PublishVo publishVo = new PublishVo();
	publishVo.setByPublishId(byPublishId);
	publishVo.setByPublishId2(byPublishId2);
	publishVo.setByPublishId3(byPublishId3);
		return publishVo;
	}
	@Override
	public  List<EduPublishhomework> getPageByClassId(Page<EduPublishhomework> pageParam, PublishQuery searchObj) {
		 List<EduPublishhomework> byClassId = baseMapper.getByClassId(pageParam, searchObj.getClassId());
	return byClassId;
	}


}
